package com.controller;

import com.pojo.Consumption;
import com.pojo.User;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class UserPageController {

    @Autowired
    private UserService userService;

    @GetMapping("/user-page")
    public String showUserPage(Model model) {
        // 假设用户 ID 为 2
        int userId = 2;
        User user = userService.getUserById(userId);
        List<Consumption> consumptionRecords = userService.getConsumptionRecords(userId);

        model.addAttribute("user", user);
        model.addAttribute("consumptions");

        return "user-page";
    }
}